<template>
  <el-container class="home_container">
    <el-header>
        <div class="block">
            <el-image class="logo" :src="require('@/assets/img/logo.png')" ></el-image>
            <div class="home_title">创卷云CEPC</div>
        </div>
      <div class="home_userinfoContainer">
        <el-dropdown @command="handleCommand">
          <span class="el-dropdown-link home_userinfo">
            <i class="el-icon-user-solid el-icon--right home_userinfo"></i>
          </span>
          <el-dropdown-menu slot="dropdown">
            <el-dropdown-item command="logout" 
              >退出登录</el-dropdown-item
            >
          </el-dropdown-menu>
        </el-dropdown>
      </div>
    </el-header>
    <el-container>
      <el-aside width="200px">
          <div class="user">
              <el-image class="avatar" :src="require('@/assets/img/blank.jpg')"></el-image>
              <div class="nickName">
                <span>CEPC前端</span>
              </div>
          </div>
        <el-menu
          default-active="0"
          v-if="isShow"
          class="el-menu-vertical-demo"
          style="background-color: #ECECEC"
          router
        >
          <template
            v-for="(item, index) in this.$router.options.routes"
            v-if="!item.hidden"
          >
            <el-submenu
              :index="index + ''"
              v-if="item.children.length > 1"
              :key="index"
            >
              <template slot="title">
                <i :class="item.iconCls"></i>
                <span>{{ item.name }}</span>
              </template>
              <el-menu-item
                v-for="child in item.children"
                v-if="!child.hidden"
                :index="child.path"
                :key="child.path"
              >
                {{ child.name }}
              </el-menu-item>
            </el-submenu>
            <template v-else>
              <el-menu-item :index="item.children[0].path">
                <i :class="item.children[0].iconCls"></i>
                <template slot="title">
                    <span style="width:100%">{{ item.children[0].name }}</span>
                    <!-- <span>{{item.children[0].desc}}</span> -->
                </template>
              </el-menu-item>
            </template>
          </template>
        </el-menu>
      </el-aside>
      <el-container>
        <el-main>
          <el-breadcrumb separator-class="el-icon-arrow-right">
            <el-breadcrumb-item :to="{ path: '/home' }"
              >首页</el-breadcrumb-item
            >
            <el-breadcrumb-item
              v-text="this.$router.currentRoute.name"
            ></el-breadcrumb-item>
          </el-breadcrumb>
          <keep-alive>
            <router-view v-if="this.$route.meta.keepAlive"></router-view>
          </keep-alive>
          <router-view v-if="!this.$route.meta.keepAlive"></router-view>
        </el-main>
      </el-container>
    </el-container>
  </el-container>
</template>
<script>
import { getRequest } from "../utils/api";
import { getCookieByKey } from '../utils/cookies';
import { getAllCookies } from '../utils/cookies';
export default {
  methods: {
    handleCommand(command) {
      var _this = this;
      if (command == "logout") {
        this.$confirm("注销登录吗?", "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(
          function() {
            _this.$store.commit("logout");
            _this.currentUserName = "游客";
            _this.$router.replace({ path: "/" });
          },
          function() {
            //取消
          }
        );
      }
    },
    reload() {
      this.isShow = false;
      this.$nextTick(() => {
        this.isShow = true;
      });
    }
  },
  mounted: function() {
    var _this = this;
    let userName = this.$store.state.nickname;
    if (userName != null && userName != undefined) {
      this.currentUserName = userName;
    } else {
      this.currentUserName = "游客";
    }
  },
  data() {
    return {
      currentUserName: "",
      isShow: true,
      state: true,
    };
  }
};
</script>
<style>
.home_container {
  height: 100%;
  position: absolute;
  top: 0px;
  left: 0px;
  width: 100%;
}

.el-header {
  background-color: white;
  border-width: 0 0 2px;
  border: 1px solid transparent;
  border-color: #eeeeee;
  /* background-color: #20a0ff; */
  color: #333;
  text-align: center;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.el-aside {
  /* background-color: #ececec; */
  background-color: #333333;
}

.el-main {
    background-color: #eeeeee;
}

.el-main {
  
  color: #000;
  text-align: center;
}

.home_title {
  color: #777777;
  font-size: 12px;
  display: inline;
}

.home_userinfo {
  color: red;
  cursor: pointer;
}

.home_userinfoContainer {
  display: inline;
  margin-right: 20px;
}

.user {
    padding: 5px;
    padding-top: 15px;
}

.nickName {
    color: #fff;
    font-size: 14px;
    padding-top: 10px;
    padding-bottom: 15px;
}

.avatar {
    width:140px; 
    height: 140px; 
    border-radius:50%;
}

.logo {
    width:15px; 
    height: 15px; 
}

.desc {
    font-size: 10px;
}
</style>
